<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<div id="app">
    <h2>{{message}}</h2>
    <h2>计数：{{counter}}</h2>
    <!--<button v-on:click="counter++">+</button>
    <button v-on:click="counter&#45;&#45;">-</button>-->
    <button v-on:click="add">+</button>
    <button v-on:click="subtract">-</button>
</div>


<script src="../../js/vue.js"></script>
<script>
    const obj = {
        message: "案例-计数器",
        counter: 0
    };

    const vue = new Vue({
        el: "#app",
        data: obj,
        methods: {
            add: function () {
                this.counter++;
                console.log("点击了'+'按钮");
            },
            subtract: function () {
                this.counter--;
                console.log("点击了'-'按钮");
            }
        }
    });
</script>
</body>
</html>